package com.mzw.huaxiarealestatebackend.controller;

import com.mzw.huaxiarealestatebackend.common.utils.DataResult;
import com.mzw.huaxiarealestatebackend.entity.Screenshot;
import com.mzw.huaxiarealestatebackend.screen.ScheduledTask;
import com.mzw.huaxiarealestatebackend.service.ScreenshotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.List;

/**
 * (Screenshot)表控制层
 *
 * @author makejava
 * @since 2024-01-05 14:07:58
 */
@RestController
@RequestMapping("screenshot")
public class ScreenshotController {
    /**
     * 服务对象
     */
    @Autowired
    private ScreenshotService screenshotService;

    @Autowired
    private ScheduledTask screenshotTask;

    @PostMapping("/startTask")
    public String startScreenshotTask(@RequestParam("userId") String userId) {
        // TODO: 根据实际情况获取用户ID

        // 启动定时截图任务
        screenshotTask.setUserId(userId);
        screenshotTask.triggerScreenshotTask();
        return "Screenshot task started successfully!";
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public DataResult queryAll(){
        List<Screenshot> screenshots = this.screenshotService.queryAll();
        return DataResult.ok(screenshots);
    }

}